
#ifndef _WRITECNTCACH_H_
#define _WRITECNTCACH_H_ 

#include <windows.h>
#include "falmain.h"
#include "log2physmap.h"



class WtCntCach
{
public:
	WtCntCach(DWORD dwStartLogSector, DWORD dwSectNumb);
	virtual ~WtCntCach(){ DeInitWtCntCache();};

public:
	virtual BOOL InitWtCntCache(){ return TRUE;};
	virtual VOID DeInitWtCntCache(){};

	virtual BOOL GetWtCnt(SECTOR_ADDR sectorAddr, SectExInfo* pSectExInfo)=0;
	virtual BOOL CacheWtCnt(SECTOR_ADDR sectorAddr, SectExInfo* pSectExInfo)=0;
	virtual BOOL UncacheWtCnt(SECTOR_ADDR sectorAddr)=0;
protected:
	DWORD m_dwStartLogSect;
	DWORD m_dwNumLogSect;
};

class WtCntCachNormal: public WtCntCach
{
public:
	WtCntCachNormal(DWORD dwStartLogSector, DWORD dwSectNumb, DWORD dwSectPerBlock);
	
public:
	BOOL InitWtCntCache();
	VOID DeInitWtCntCache();

	BOOL GetWtCnt(SECTOR_ADDR sectorAddr, SectExInfo* pSectExInfo);
	BOOL CacheWtCnt(SECTOR_ADDR sectorAddr, SectExInfo* pSectExInfo);
	BOOL UncacheWtCnt(SECTOR_ADDR sectorAddr);

private:
    DWORD m_dwCacheSize;
    DWORD m_dwCacheSizeMask;
	DWORD* m_pdwWtCacheAddrS;
	SectExInfo* m_psectExInfoS;
	DWORD m_dwLastId;
};

class WtCntCachStartUp: public WtCntCach
{
public:
	WtCntCachStartUp(DWORD dwStartLogSector, DWORD dwSectNumb);
	virtual ~WtCntCachStartUp();
	
public:
	BOOL InitWtCntCache();
	VOID DeInitWtCntCache();

	BOOL GetWtCnt(SECTOR_ADDR sectorAddr, SectExInfo* pSectExInfo);
	BOOL CacheWtCnt(SECTOR_ADDR sectorAddr, SectExInfo* pSectExInfo);
	BOOL UncacheWtCnt(SECTOR_ADDR sectorAddr){ return FALSE;};
private:
#define  MASTER_CHACHE_TABLE_SIZE      256
    SectExInfo* m_pSectExInfo[MASTER_CHACHE_TABLE_SIZE];
	DWORD m_dwNumSectorsPerSecTable;
};

#endif	//#ifndef _WRITECNTCACH_H_

